/**
 *
 * © Bahadir Zeren 2011
 * bzeren@gmail.com
 * No warranties, express or implied, are made for this program.
 *
 */

package org.baatar.log;

import org.apache.log4j.Appender;
import org.apache.log4j.Layout;
import org.apache.log4j.spi.ErrorHandler;
import org.apache.log4j.spi.Filter;
import org.apache.log4j.spi.LoggingEvent;

/**
 *
 * @author B_ZEREN
 */
public class UIAppender implements Appender {

    private String name = null;
    private IUILogger uiLogger = null;

    public UIAppender(IUILogger uiLogger) {
        super();
        this.uiLogger = uiLogger;
    }

    @Override
    public void addFilter(Filter filter) {
    }

    @Override
    public Filter getFilter() {
        return null;
    }

    @Override
    public void clearFilters() {
    }

    @Override
    public void close() {
    }

    @Override
    public void doAppend(LoggingEvent le) {
        if (uiLogger != null)
            uiLogger.addLog(le.getMessage().toString());
    }

    @Override
    public void setName(String string) {
        this.name = string;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setErrorHandler(ErrorHandler eh) {
    }

    @Override
    public ErrorHandler getErrorHandler() {
        return null;
    }

    @Override
    public void setLayout(Layout layout) {
    }

    @Override
    public Layout getLayout() {
        return null;
    }

    @Override
    public boolean requiresLayout() {
        return false;
    }

    public IUILogger getUILogger() {
        return uiLogger;
    }

    public void setUILogger(IUILogger uiLogger) {
        this.uiLogger = uiLogger;
    }

}
